package com.mysen.sso.model;

import java.util.Date;
import java.util.Map;
import java.util.Set;

import com.mysen.exception.MaikeServiceException;
import com.mysen.model.BaseModel;
import com.mysen.model.Response;

public class Permission extends BaseModel {
	private static final long serialVersionUID = 1L;
	
	public static interface PermissionType{
		public static final Byte SYSTEM = 1;
		public static final Byte MODEL = 2;
		public static final Byte MENU = 3;
		public static final Byte BUTTON = 4;
		public static final Byte LINK = 5;
		public static String toString(Byte b) {
			if(SYSTEM.equals(b))
				return "SYSTEM";
			if(MODEL.equals(b))
				return "MODEL";
			if(MENU.equals(b))
				return "MENU";
			if(BUTTON.equals(b))
				return "BUTTON";
			if(LINK.equals(b))
				return "LINK";
			throw new MaikeServiceException("not support type!");
		}
		public static Byte valueOf(String type) {
			if("SYSTEM".equalsIgnoreCase(type)) {
				return SYSTEM;
			}
			if("MODEL".equalsIgnoreCase(type)) {
				return MODEL;
			}
			if("MENU".equalsIgnoreCase(type)) {
				return MENU;
			}
			if("BUTTON".equalsIgnoreCase(type)) {
				return BUTTON;
			}
			if("LINK".equalsIgnoreCase(type)) {
				return LINK;
			}
			throw new MaikeServiceException("not support type!");
		}
	}

	public static interface PermissionMethod{
		public static final Byte GET = 1;
		public static final Byte POST = 2;
		public static final Byte PUT = 3;
		public static final Byte DELETE = 4;
		public static final Byte OPTIONS = 5;
		public static final Byte PATCH = 6;
		public static final Byte HEAD = 7;
		public static String toString(Byte b) {
			if(GET.equals(b))
				return "GET";
			if(POST.equals(b))
				return "POST";
			if(PUT.equals(b))
				return "PUT";
			if(DELETE.equals(b))
				return "DELETE";
			if(OPTIONS.equals(b))
				return "OPTIONS";
			if(PATCH.equals(b))
				return "PATCH";
			if(HEAD.equals(b))
				return "HEAD";
			throw new MaikeServiceException("not support method!");
		}
		
		public static Byte valueOf(String method) {
			if("GET".equalsIgnoreCase(method))
				return GET;
			if("POST".equalsIgnoreCase(method))
				return POST;
			if("PUT".equalsIgnoreCase(method))
				return PUT;
			if("DELETE".equalsIgnoreCase(method))
				return DELETE;
			if("PATCH".equalsIgnoreCase(method))
				return PATCH;
			if("OPTIONS".equalsIgnoreCase(method))
				return OPTIONS;
			if("HEAD".equalsIgnoreCase(method))
				return HEAD;
			throw new MaikeServiceException("not support method!");
		}
	}
	
    private String permissionId;

    private String permissionName;

    private String permissionImage;

    private String permissionDesc;

    private String permissionUrl;

    private Byte permissionType;

    private String permissionPid;
    
    private Byte permissionMethod;
    
    private Map<String,Object> permissionExt;

    private Byte permissionOrder;

    private Byte status;

    private String cuser;

    private Date cdate;

    private Set<Role> roles;
    
    public Set<Role> getRoles() {
		return roles;
	}

	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}

	public String getPermissionId() {
        return permissionId;
    }

    public void setPermissionId(String permissionId) {
        this.permissionId = permissionId == null ? null : permissionId.trim();
    }

    public String getPermissionName() {
        return permissionName;
    }

    public void setPermissionName(String permissionName) {
        this.permissionName = permissionName == null ? null : permissionName.trim();
    }

    public String getPermissionImage() {
        return permissionImage;
    }

    public void setPermissionImage(String permissionImage) {
        this.permissionImage = permissionImage == null ? null : permissionImage.trim();
    }

    public String getPermissionDesc() {
        return permissionDesc;
    }

    public void setPermissionDesc(String permissionDesc) {
        this.permissionDesc = permissionDesc == null ? null : permissionDesc.trim();
    }

    public String getPermissionUrl() {
        return permissionUrl;
    }

    public void setPermissionUrl(String permissionUrl) {
        this.permissionUrl = permissionUrl == null ? null : permissionUrl.trim();
    }

    public Byte getPermissionType() {
        return permissionType;
    }

    public void setPermissionType(Byte permissionType) {
    	if(permissionType < 1 || permissionType > 5) {
    		throw new MaikeServiceException(Response.MSG_PARAM_ERROR);
    	}
        this.permissionType = permissionType;
    }

    public String getPermissionPid() {
        return permissionPid;
    }

    public void setPermissionPid(String permissionPid) {
        this.permissionPid = permissionPid;
    }

    public Byte getPermissionOrder() {
        return permissionOrder;
    }

    public void setPermissionOrder(Byte permissionOrder) {
        this.permissionOrder = permissionOrder;
    }

    public Byte getStatus() {
        return status;
    }

    public void setStatus(Byte status) {
        this.status = status;
    }

    public String getCuser() {
        return cuser;
    }

    public void setCuser(String cuser) {
        this.cuser = cuser == null ? null : cuser.trim();
    }

    public Date getCdate() {
        return cdate;
    }

    public void setCdate(Date cdate) {
        this.cdate = cdate;
    }

	public Byte getPermissionMethod() {
		return permissionMethod;
	}

	public void setPermissionMethod(Byte permissionMethod) {
    	if(permissionMethod < 1 || permissionMethod > 7) {
    		throw new MaikeServiceException(Response.MSG_PARAM_ERROR);
    	}
		this.permissionMethod = permissionMethod;
	}

	public Map<String, Object> getPermissionExt() {
		return permissionExt;
	}

	public void setPermissionExt(Map<String, Object> permissionExt) {
		this.permissionExt = permissionExt;
	}
}